package user.zc.action.comp;

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.util.Enumeration;
import java.util.function.Consumer;

/**
 * @author zhouchuang
 * @date 2023/8/11 10:12
 */
public abstract class Action<R> {
    private Consumer<R> callback;
    public Action(Consumer<R> callback) {
        this.callback = callback;
        Font font = new Font("等线", Font.BOLD, 16);
        initGlobalFontSetting(font);
    }
    public void call(R t){
        callback.accept(t);
    }

    //设置全局字体
    private void initGlobalFontSetting(Font fnt){
        FontUIResource fontRes = new FontUIResource(fnt);
        for(Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements();){
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if(value instanceof FontUIResource)
                UIManager.put(key, fontRes);
        }
    }
    protected boolean checkRequired(IField... fields){
        for (IField field : fields) {
            if(field.getText().length()==0){
                JOptionPane.showMessageDialog(null, "【"+field.getLabel()+"】为必填项");
                return false;
            }
        }
        return true;
    }
}
